<%@page import="com.tubeonfire.entity.Channel"%>
<%@page import="com.tubeonfire.model.admin.ChannelModel"%>
<%@page import="com.google.appengine.api.blobstore.BlobKey"%>
<%@page import="com.google.appengine.api.images.ImagesServiceFactory"%>
<%@page import="com.google.appengine.api.images.ImagesService"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	ChannelModel model = (ChannelModel)request.getAttribute("result");
	String url = (String)request.getAttribute("url");
	List<Channel> list = model.getListResult();
	ImagesService imagesService = ImagesServiceFactory.getImagesService(); 	
%>
<jsp:include page="/admin/elements/header.jsp">
	<jsp:param value="Channel Manager" name="title"/>
</jsp:include>
<script type="text/javascript" src="/admin/js/custom/media.js"></script>
<script type="text/javascript" src="/admin/js/mine/list_channel.js"></script>
	<body class="loggedin">
		<jsp:include page="/admin/elements/top.jsp"/>
	    <!-- START OF MAIN CONTENT -->
	    <div class="mainwrapper">
	     	<div class="mainwrapperinner">  	     		       	       
				<jsp:include page="/admin/elements/left.jsp">
					<jsp:param value="channel" name="current_page"/>
				</jsp:include>						              	                   
	        	<div class="maincontent noright">
	        		<div class="maincontentinner">	
        				<ul class="maintabmenu multipletabmenu">
		                	<li class="current"><a href="/admin/channel/list">Manage Channel</a></li>		                                       
		                </ul>            			               
		                     
	                	<div class="content">	
	                	<jsp:include page="/admin/elements/message.jsp"/>	
	                	<%
		                	if(model!=null&&list.size()>0){
		                %>          	                    
	                    	<div class="contenttitle">
	                    		<h2 class="image"><span>List Channel</span></h2>
	                    	</div>
	                    	<br />
		                    <ul class="imagelist">
		                    <%
		                    	for(Channel obj : list){		
		                    		String imgUrl = obj.getImageKey();
									if(!imgUrl.contains("http://")){
										try{
											BlobKey blobKey = new BlobKey(imgUrl);
											imgUrl = imagesService.getServingUrl(blobKey);
										}catch(Exception e){
											imgUrl = "/images/tube.png";
										}														
									}			                    		
		                    %>
		                    	<li style="width: 280px">
		                    		<a href="/admin/channel/edit?id=<%=obj.getId() %>" title="<%=obj.getTitle()%>" style="display: block;height:150px;overflow: hidden;background:#000;">
		                    			<img src="<%=imgUrl %>" alt="" style="width: 250px; height: auto;"/>
		                    		</a>		                    		    
		                        	<span style="text-align: right;">
		                        		<a href="/admin/channel/edit?id=<%=obj.getId() %>" class="name" title="Edit playlist <%=obj.getTitle()%>" style="display: block;width: 100%;"><%=obj.getTitle() %></a>
		                        		<a class="btn btn4 btn_tubes" href="/admin/tube/list?channelId=<%=obj.getId() %>" rel="<%=obj.getTitle()%>" title="View all tubes of this channel" ></a>		                        		
		                        		<a class="btn btn4 btn_flag" href="<%=obj.getId() %>" rel="<%=obj.getTitle()%>" title="Bump" ></a>
		                        		<a class="btn btn4 btn_pencil" href="/admin/channel/edit?id=<%=obj.getId() %>"  title="Click to edit channel information"></a>		                        		
		                        		<a class="btn btn4 btn_trash" href="<%=obj.getId() %>" rel="<%=obj.getTitle()%>" title="Click to delete channel"></a>
		                        	</span>
		                        </li>		                        
		                     <%
		                    	}		                	
		                     %>                    
		                    </ul>		      
		                    <%
		                	}
		                    %>                                                   
	                    	<br clear="all" />	   	                    	
	                </div>
	               
	                <!--content-->	                
	            </div><!--maincontentinner-->
				<jsp:include page="/admin/elements/bottom.jsp"></jsp:include>                    	           	
	        </div><!--maincontent-->	                        
	     	</div><!--mainwrapperinner-->
	    </div><!--mainwrapper-->
		<!-- END OF MAIN CONTENT -->    
		<div id="opacity"></div>
		<img id="image_loadder" src="/admin/images/ajax-loader.gif">    
	</body>
</html>
